<?php
namespace Home\Controller;
use Think\Controller;
use Think\Model;



class IndexController extends AuthController {

    public function mytry(){
        /*
         * 读取log 文件数据
         * fopen(),fread('1.text',r),fclose();
         */
        $myfile = fopen("Application/Runtime/Logs/Home/18_01_09.log", "r") or die("Unable to open file!");
        echo fread($myfile,filesize("Application/Runtime/Logs/Home/18_01_09.log"));
        fclose($myfile);die;
        // 输出单字符直到 end-of-file
        while(!feof($myfile)) {
            echo fgetc($myfile)."<br/>";
        }

        die;
    }

    public function index(){
        $powers= $this->GetMainPowers();
        $this->assign('powers', $powers);
        $data['sitename']='我的管理后台';
        $this->assign('data', $data);
        $this->display();
    }

    function del_dir($dir) {
        $dh=opendir($dir);
        while ($file=readdir($dh)) {
            if($file!="." && $file!="..") {
                $fullpath=$dir."/".$file;
                if(!is_dir($fullpath)) {
                    @unlink($fullpath);
                } else {
                    $this->del_dir($fullpath);
                }
            }
        }
        closedir($dh);
        if(rmdir($dir)) {
            return true;
        } else {
            return false;
        }
    }

    public function Eliminate(){
        $rel['code'] = 0;
        $rel['msg'] = '清除失败';
        $rtim= $this->del_dir(APP_PATH.'/Runtime');
        cookie(null);   //删除个cookie 缓存
        if($rtim){
            $rel['code'] = 1;
            $rel['msg'] = '清除成功';
        }
        $this->ajaxReturn($rel);
    }
}